﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using DAL;
using System.Web.Security;
namespace BLL
{
    public class UserInfoBll
    {
        //增加实体对象
        public static bool Add(UserInfo o)
        {
            return UserInfoDal.Add(o);
        }
        //根据id删除实体对象
        public static bool Delete(int id)
        {
            return UserInfoDal.Delete(id);
        }
        //根据id修改实体对象
        public static bool Update(UserInfo o)
        {
            return UserInfoDal.Update(o);
        }
        //查询 所有记录 
        public static List<UserInfo> SelectAll()
        {
            return UserInfoDal.SelectAll("");
        }
        //根据id查询单个实体对象
        public static UserInfo SelectOne(int id)
        {
            return UserInfoDal.SelectOne(id);
        }
        //注册
        public static bool Register(UserInfo obj)
        {
            //给用户密码加密
            obj.Pswd = FormsAuthentication.HashPasswordForStoringInConfigFile(obj.Pswd, "md5");
            //调用数据访问类的添加方法
            return UserInfoDal.Add(obj);
        }
        //登录
        public static UserInfo Login(string user, string pswd)
        {
            //加密
            pswd = FormsAuthentication.HashPasswordForStoringInConfigFile(pswd, "md5");
            List<UserInfo> ret = UserInfoDal.SelectAll(string.Format(" Username='{0}' and Pswd='{1}'", user, pswd));
            //判断是否只是有一条数据
            if (ret != null && ret.Count > 0)
            {
                return ret[0];
            }
            else
            {
                return null;
            }

        }
        //获取记录总数
        public static int GetTotal()
        {
            return UserInfoDal.GetTotal();
        }
        //分页查询
        public static List<UserInfo> SelectAllByPage(int pageSize, int PageNo)
        {
            return UserInfoDal.SelectAllByPage(pageSize, PageNo);
        } 
    }
}
